/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ipti.br.tag.entity;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import org.ipti.br.tag.util.EncryptionUtil;

/**
 *
 * @author luancorumba
 */
@Entity
public class Work extends AbstractEntity{
    private static final long serialVersionUID = 1L;
    
    @ManyToOne
    private WorkTopic topic;

    @ManyToOne
    private Discipline discipline;
    
    @ManyToOne
    private Organization organization;

    public Work() {
    }

    @Override
    public void generateHash(){
        if(getId() == null){
            String actorHashString = ""
                    + ((this.getDiscipline() != null) ? this.getDiscipline().getId() :"")
                    + ((this.getOrganization() != null) ? this.getOrganization().getId() :"")
                    + ((this.getTopic() != null) ? this.getTopic().getId() : "");
            this.setId(Long.valueOf(EncryptionUtil.encrypt(actorHashString).hashCode()));
        }
    }

    public Work(WorkTopic topic, Discipline discipline, Organization organization) {
        this.topic = topic;
        this.discipline = discipline;
        this.organization = organization;
    }

    public Discipline getDiscipline() {
        return discipline;
    }

    public void setDiscipline(Discipline discipline) {
        this.discipline = discipline;
    }

    public Organization getOrganization() {
        return organization;
    }

    public void setOrganization(Organization organization) {
        this.organization = organization;
    }

    public WorkTopic getTopic() {
        return topic;
    }

    public void setTopic(WorkTopic topic) {
        this.topic = topic;
    }

    @Override
    public String toString() {
        return "entity.WorkPlan[ id=" + this.getId() + " ]";
    }
    
}
